package com.ruowei.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class StaticResourceConfiguration extends WebMvcConfigurerAdapter {

    private final String staticDir;
    private final String uploadDir;

    public StaticResourceConfiguration(ApplicationProperties applicationProperties) {
        this.staticDir = applicationProperties.getStaticDir();
        this.uploadDir = applicationProperties.getUploadDir();
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //页面资源：html、css、js、页面图片元素等内置资源，属于前端工程的一部分
        registry.addResourceHandler("/static/**").addResourceLocations("file:" + staticDir);
        //用户数据：用户在使用系统过程中产生的图片、文档等数据
//        registry.addResourceHandler("/resource/**").addResourceLocations("file:" + resourceDir);
        registry.addResourceHandler("/upload/**").addResourceLocations("file:" + uploadDir);
//        registry.addResourceHandler("/liaochengImgCache/**").addResourceLocations("file:" + liaochengImgCache);
//        registry.addResourceHandler("/shuxiyanlian/wordExport/**").addResourceLocations("file:/shuxiyanlian/wordExport/");
        super.addResourceHandlers(registry);
    }
}
